<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var assetsDataGrid;
    $(function() {
        assetsDataGrid = $('#assetsDataGrid').datagrid({
            url : '${path }/app/assets/dataGrid',
            fit : true,
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'sequence',
	        sortOrder : 'asc',
            pageSize : 10,
            pageList : [ 10, 20, 30, 40, 50 ],
            columns : [ [ {
                width : '150',
                title : '资产名称',
                field : 'goods_name',
                sortable : true
            },{
                width : '80',
                title : '创建时间',
                field : 'create_time',
                sortable : true
            },{
                width : '50',
                title : '金额',
                field : 'value'
            },{
                width : '100',
                title : '经手人',
                field : 'operator',
                sortable : true
            },{
                width : '100',
                title : '操作人',
                field : 'userName',
                sortable : true
            },{
                width : '120',
                title : '规格',
                field : 'specifications',
                sortable : true
            },{
                width : '80',
                title : '录入时间',
                field : 'insert_time',
                sortable : true
            },{
                width : '60',
                title : '状态',
                field : 'status',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                    case 0:
                        return '停用';
                    case 1:
                        return '正常';
                    }
                }
            } , {
                field : 'action',
                title : '操作',
                width : 130,
                formatter : function(value, row, index) {
                   var str = '';
                        <shiro:hasPermission name="/app/assets/edit">
                            str += $.formatString('<a href="javascript:void(0)" class="assets-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editAssetsFun(\'{0}\');" >修改</a>', row.id);
                        </shiro:hasPermission>
                        <shiro:hasPermission name="/app/assets/delete">
                            str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                            str += $.formatString('<a href="javascript:void(0)" class="assets-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteAssetsFun(\'{0}\');" >删除</a>', row.id);
                        </shiro:hasPermission> 
                    return str;
                }
            } 
            ] ],
            onLoadSuccess:function(data){
                $('.assets-easyui-linkbutton-edit').linkbutton({text:'修改'});
                $('.assets-easyui-linkbutton-del').linkbutton({text:'删除'});
            },
            toolbar : '#assetsToolbar'
        });
    });
      //获取父id
    function getAssociationId(){
    	var associationId=$("#associationId").val();
    	return associationId;
    }  
     function editAssetsFun(id) {
        if (id == undefined) {
            var rows = assetsDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            assetsDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : 600,
            height : 400,
            href : '${path }/app/assets/edit?id='+id
            ,buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = assetsDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#assetsEditForm');
                    f.submit();
                }
            } ] 
        });
    }
   function addAssetsFun() {
        parent.$.modalDialog({
            title : '添加',
            width : 600,
            height : 400,
            href : '${path }/app/assets/add',
            buttons : [ {
                text : '添加',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = assetsDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#assetsEditForm');
                    f.submit();
                }
            } ]
        });
    } 
    function deleteAssetsFun(id) {
     if (id == undefined) {
        	var rows = assetsDataGrid.datagrid('getSelections');
        	id = rows[0].id;
        } else {
            assetsDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除当前信息？', function(b) {
            if (b) {
                progressLoad();
                $.post('${path }/app/assets/delete', {
                    id : id
                }, function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        assetsDataGrid.datagrid('reload');
                    } else {
                        parent.$.messager.alert('错误', result.msg, 'error');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }
    
    function searchAssetsFun() {
        assetsDataGrid.datagrid('load', $.serializeObject($('#searchAssetsForm')));
    }
    function cleanAssetsFun() {
        $('#searchAssetsForm input').val('');
        assetsDataGrid.datagrid('load', {});
    }
</script>

<div class="easyui-layout" data-options="fit:true,border:false">
		<div data-options="region:'center',split:true" title="资产信息列表" style="width:100%;">
			 <table id="assetsDataGrid" data-options="fit:true,border:false"></table>
		</div>
	</div>
<div id="assetsToolbar" style="display: none;">
        <form id="searchAssetsForm">
       		<input name="associationId" type="hidden" id="associationId" value=""/>
            <table>
                <tr>
                    <th>资产名称:</th>
                    <td><input name="goodsName" placeholder="请输入资产名称"/>
                     	<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="searchAssetsFun();">查询</a>
                     	<shiro:hasPermission name="/app/assets/add">
					        <a onclick="addAssetsFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus '">添加</a>
					    </shiro:hasPermission>
                	</td>
                </tr>
            </table>
        </form>
</div>